package xyz.gzdxc.common.mysql.repository;

import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import xyz.gzdxc.common.mysql.entity.SessionEntity;

import java.util.Date;

@Repository
public interface SessionRepository extends CrudRepository<SessionEntity, Long> {
    /**
     * save the session infomation after the user login
     *
     * @param sessionEntity
     * @return
     */
    @Override
    SessionEntity save(SessionEntity sessionEntity);

    /**
     * find the session entity by session string
     *
     * @param loginSession
     * @return
     */
    SessionEntity findByLoginSession(String loginSession);

    /**
     * update the session updateTime by id
     *
     * @param updateTime
     * @param id
     * @return
     */
    @Modifying
    @Query("update xh_cm_session set update_time = :updateTime where id = :id")
    boolean modifyUpdateTimeById(@Param("updateTime") Date updateTime, @Param("id") Long id);
}
